package org.example.builder;

public class Computer {
    // 必需部件
    private String cpu;
    private String ram;

    // 可选部件
    private String storage;
    private String gpu;
    private String os;

    // 私有构造方法，只能通过Builder构建
    private Computer(Builder builder) {
        this.cpu = builder.cpu;
        this.ram = builder.ram;
        this.storage = builder.storage;
        this.gpu = builder.gpu;
        this.os = builder.os;
    }

    // Getters
    public String getCpu() { return cpu; }
    public String getRam() { return ram; }
    public String getStorage() { return storage; }
    public String getGpu() { return gpu; }
    public String getOs() { return os; }

    @Override
    public String toString() {
        return "Computer{" +
                "cpu='" + cpu + '\'' +
                ", ram='" + ram + '\'' +
                ", storage='" + storage + '\'' +
                ", gpu='" + gpu + '\'' +
                ", os='" + os + '\'' +
                '}';
    }

    // 建造者
    public static class Builder {
        // 必需参数
        private final String cpu;
        private final String ram;

        // 可选参数 - 初始化默认值
        private String storage = "1TB HDD";
        private String gpu = "Integrated";
        private String os = "Windows 10 Home";

        public Builder(String cpu, String ram) {
            this.cpu = cpu;
            this.ram = ram;
        }

        public Builder storage(String storage) {
            this.storage = storage;
            return this;
        }

        public Builder gpu(String gpu) {
            this.gpu = gpu;
            return this;
        }

        public Builder os(String os) {
            this.os = os;
            return this;
        }

        public Computer build() {
            return new Computer(this);
        }
    }
}
